import React from 'react';
import CommonListsIndex from '../../../../../../components/CommonLists/index';
import PublishHistoryList from './list';

class PublishHistory extends CommonListsIndex {
  constructor(props) {
    super(props);
    this.api = 'history';
    this.queryPanigation = {
      page: 1,
      size: 10,
    };
    this.listsComponent = PublishHistoryList;
  }

  componentDidMount() {
    this.queryParams.id = this.props.match.params.id;
    this.freshQueryList();
  }

  getColumns = () => [
    {
      title: '版本',
      dataIndex: 'version',
    },
    {
      title: (
        <>
          {this.getFilterTitle(
            '状态',
            [
              {
                value: 1,
                name: '发布',
              },
              {
                value: 0,
                name: '停用',
              },
            ],
            'status',
            this.refreshTableFilter,
            ['value', 'name']
          )}
        </>
      ),
      dataIndex: 'statusLabel',
    },
    {
      title: '发布备注',
      dataIndex: 'desc',
    },
    {
      title: '发布时间',
      dataIndex: 'publishTime',
    },
  ];

  onChangePagination = (pageNumber, type = 'current_page') => {
    const t = type === 'current_page' ? 'page' : 'size'
    this.updatePanagaition && this.updatePanagaition({
      [t]: pageNumber,
    });
    this.freshQueryList();
  };

  render() {
    const { records, current, total, size } = this.state;
    const ListsComponent = this.listsComponent;
    return (
      <div className='detail'>
        <ListsComponent
          {...this.props}
          list={records}
          currentPage={current}
          totalCount={total}
          pageSize={size}
          rowKey='id'
          columns={this.getColumns()}
          queryList={this.freshQueryList}
          onChangePagination={this.onChangePagination}
        />
      </div>
    );
  }
}
export default PublishHistory;
